using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;

public partial class Admin_Danhsachtourthamgia : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadData();

        }
    }
    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria cri = new Criteria();
        int total = 0;


        tbTourtthamgiaCollection  tourttCollection = tbTourthamgiaBUS .Get(cri.Criter, pager.CurrentIndex, pager.PageSize,
       tbTourthamgiaCollumn .matourthamgia .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = tourttCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;

    }

    protected void pager_Command(object sender, CommandEventArgs e)
    {
        pager.CurrentIndex = Convert.ToInt32(e.CommandArgument);
        LoadData();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item
        || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbTourthamgia  tourtg = (tbTourthamgia )e.Item.DataItem;


            Literal lit_mtm = (Literal)e.Item.FindControl("lit_mtm");
            lit_mtm.Text = tourtg.Matourmo.ToString ();

            tbKhachhang  kh = tbKhachhangBUS .GetByID(tourtg.Makh );
            if (kh != null)
            {
                Label  lit_kh = (Label )e.Item.FindControl("lit_kh");
              lit_kh.Text = kh.Tenkh ;
            }


            Literal  lit_snl= (Literal )e.Item.FindControl("lit_snl");
            lit_snl .Text = tourtg.Soluongnguoilon.ToString () ;



            Literal lit_snn = (Literal)e.Item.FindControl("lit_snn");
            lit_snn.Text = tourtg.Soluongnguoinho.ToString () ;

            HyperLink hp_sua = (HyperLink)e.Item.FindControl("hp_sua");
            hp_sua.NavigateUrl = "~/Admin/Suatourthamgia.aspx?id=" + tourtg.Matourthamgia .ToString();





        }
    }
    protected void lbt_xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_xoa");
            if (cb_xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbTourthamgia  tourtg= tbTourthamgiaBUS .GetByID(id);
                tbTourthamgiaBUS .Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
}
